#!/usr/bin/python

from ftplib import FTP
import urllib
import time
from ConfigParser import ConfigParser

from pyfi import PyFi

def main():
    ip = get_exteral_ip()
    
    # set up options as specified in the config file
    conf = ConfigParser()
    conf.read("config.conf")
    
    host = conf.get("FTP", "host")
    user = conf.get("FTP", "user")
    password = conf.get("FTP", "password")
    
    # open ftp connection
    ftp = FTP(host, user, password)
    
    # test code
    print ip
    print ftp.retrlines("LIST")
    
    # close ftp connection
    ftp.quit()

def get_exteral_ip():
    # super-light page for 'www.whatismyip.com' automated external ip lookup
    wimi_address = "http://www.whatismyip.com/automation/n09230945.asp"
    
    # get our ip as a string from the site and return it
    return urllib.urlopen(wimi_address).read().strip()

if __name__ == "__main__":
    main()
